package com.dilean.impl.dao;

import org.hibernate.Hibernate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.dilean.api.model.Conversation;
import com.dilean.api.dao.ConversationDAO;
import com.dilean.impl.model.ConversationImpl;


@Repository
@Transactional(readOnly = true)
public class ConversationDAOImpl extends AbstractDAOImpl<Conversation> implements ConversationDAO {

	@Override
	public Conversation findByIdWithPersons(Integer id) {
		Conversation conversation = em.find(ConversationImpl.class, id);
		 Hibernate.initialize(conversation.getPersons()); 
		 return conversation;
	}

	@Override
	public Conversation findByIdWithMessages(Integer id) {
		Conversation conversation = em.find(ConversationImpl.class, id);
		 Hibernate.initialize(conversation.getMessages()); 
		 return conversation;
	}
}
